<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/layui/css/layui.css">
        <link rel="stylesheet" href="../../global/css/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
        <link rel="stylesheet" href="../../global/css/ztree/demo.css" type="text/css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <form class="form-horizontal" onsubmit="return false" id="form" enctype="multipart/form-data">
        <fieldset>
     <input type="hidden" id="userId" name="userId"/>
          <div class="form-group">
           <label class="col-md-2 control-label">姓名:</label>
           <div class="col-md-5">
            <input class="form-control" placeholder="姓名" type="text" name="receiveName" id="receiveName" data-bv-notempty="true" data-bv-notempty-message="收货人不能为空" />
           </div>
          </div>
           <div class="form-group">
                                      <label class="col-md-2 control-label">性别:</label>
                                      <div class="col-md-10" style="width: 120px">
                                       <select class="form-control input-sm" name="sex" id="sex">
                                       <option value="" >请选择</option>
                                       <option value="0" selected="selected">男</option>
                                       <option value="1" >女</option> </select>
                                  </div>
                                  </div>
            <div class="form-group">
                           <label class="col-md-2 control-label">联系电话:</label>
                           <div class="col-md-5">
                               <input class="form-control" placeholder="联系电话" type="text" name="receivePhone" id="receivePhone"  />
                           </div>
                       </div>
             <div class="form-group">
                            <label class="col-md-2 control-label">所在省:</label>
                            <div class="col-md-5">
                                <input readonly class="form-control" placeholder="所在省" type="text" name="addressProvince" id="addressProvince" data-bv-notempty="true" data-bv-notempty-message="省不能为空" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">所在市:</label>
                            <div class="col-md-5">
                                <input readonly class="form-control" placeholder="所在市" type="text" name="addressCity" id="addressCity" data-bv-notempty="true" data-bv-notempty-message="市不能为空" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">所在县/区:</label>
                            <div class="col-md-5">
                                <input readonly class="form-control" placeholder="所在县/区" type="text" name="addressCounty" id="addressCounty" data-bv-notempty="true" data-bv-notempty-message="县不能为空" />
                            </div>
                        </div>
            <div class="form-group">
                <label class="col-md-2 control-label">详细地址:</label>
                <div class="col-md-5">
                     <input type="text"  style="width:600px" id="addressDetail" name="addressDetail" />
                     <input readonly type="text" placeholder="经度" id="lng" name="lng" /><input readonly type="text" placeholder="纬度" id="lat" name="lat" />
            		<div id="container2" style="width:100%;height:300px"></div>
                </div>
            </div>
            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" onclick="location.href='touchList.html'">返回</button>
                        <button class="btn btn-primary" type="submit" id="open">
                            <i class="fa fa-save"></i> 下一步
                        </button>
                    </div>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<script type="text/javascript" src="../../global/js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../global/js/jq.js"></script>
<script type="text/javascript" src="../../global/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../global/js/common.js"></script>
<script type="text/javascript" src="../../global/js/libs/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="../../global/layui/layui.js"></script>
<script type="text/javascript" src="../../global/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="../../global/js/my/ztree-menu.js"></script>
<script type="text/javascript"src="https://webapi.amap.com/maps?v=1.4.10&key=5f80e00b3a03bce6ac34804ff562a19f"></script>
<script type="text/javascript"src="https://webapi.amap.com/demos/js/liteToolbar.js"></script>
<script src="https://webapi.amap.com/ui/1.0/main.js?v=1.0.11"></script>
<script src="layer/layer.js"></script>
<script src="layer/extend/layer.ext.js"></script>
<script>
  //调用父窗口的function addPersonalCenter(){}方法,在父窗口右上角增加一个个人中心按钮
  //获取选中的值
/*  function qcode(){*/
$("#open").on("click", function() {
      parent.layer.open({
                     type : 2,
                     title : '支付',
                     area : [ '600px', '600px' ],
                     fix : false, //
                     content : 'qcode.html',
                     success : function() {
                     var Index = parent.layer.getFrameIndex(window.name);
                     parent.layer.close(Index);
                                      }
                                  });
  });

</script>
<script type="text/javascript">
    layui.use(['layer', 'laydate'], function () {
        var layer = layui.layer;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#aptitudeTime'
        });
    });
    $(function(){
		initData();
	    loadmap();
	})
    function initData() {
         var id = getUrlParam("id");
         if (id != "") {
                $("#userId").val(id);
                    }
        }
    $('#form').bootstrapValidator();

    function update() {
        // 表单验证
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }

        $("form").ajaxSubmit({
            type: 'post',
            url: '/clyjAddress/saveAds',
            traditional: true,
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                layer.msg("成功", {shift: -1, time: 1000}, function () {
                          qcode();
                });
            }
        });
    }
    function loadmap() {
		var map = new AMap.Map('container2', {
			resizeEnable : true,
			zoom : 11,
			scrollWheel : true
		});
		var marker = new AMap.Marker(
				{
					position : [ $("#longitude").val(),
							$("#latitude").val() ],
					content : '<div class="markers_tip bdz_markers"><div>111</div></div>',
					offset : new AMap.Pixel(-25, -45)
				});
		mapInit(map);
		$(".loadmap:eq(1)").hide();

	}
    function mapInit(map) {
		AMap.plugin('AMap.Geolocation', function() {
		    geolocation = new AMap.Geolocation({
 				enableHighAccuracy : true, //是否使用高精度定位，默认:true
				timeout : 10000, //超过10秒后停止定位，默认：无穷大
				maximumAge : 0, //定位结果缓存0毫秒，默认：0
				convert : true, //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
				showButton : true, //显示定位按钮，默认：true
				buttonPosition : 'RT', //定位按钮停靠位置，默认：'LB'，左下角
				buttonOffset : new AMap.Pixel(10, 10), //定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
				showMarker : true, //定位成功后在定位到的位置显示点标记，默认：true
				panToLocation : true, //定位成功后将定位到的位置作为地图中心点，默认：true
				zoomToAccuracy : true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
			});
			map.addControl(geolocation);
			geolocation.getCurrentPosition();
			AMap.event.addListener(geolocation, 'complete', onComplete); //返回定位信息
			AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息
		});


		function onComplete(data) { //地图实时定位结果
			var str = [ '定位成功' ];
			str.push('经度：' + data.position.getLng());
			str.push('纬度：' + data.position.getLat());
			if (data.accuracy) {
				str.push('精度：' + data.accuracy + ' 米');
			} //如为IP精确定位结果则没有精度信息
			str.push('是否经过偏移：' + (data.isConverted ? '是' : '否'));
			AMapUI
					.loadUI(
							[ 'misc/PositionPicker' ],
							function(PositionPicker) {
								var positionPicker = new PositionPicker(
										{
											map : map,
											iconStyle : { //自定义外观
												url : 'https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png', //webapi.amap.com/ui/1.0/assets/position-picker2.png
												ancher : [ 12, 38 ],
												size : [ 19, 31 ]
											}
										});
								positionPicker.on('success', function(
										positionResult) {
									console.info(positionResult);
							/*		$("#addressDetail").val(
											positionResult.address);*/
									$("#lng").val(
											positionResult.position.lng);
									$("#lat").val(
											positionResult.position.lat);
									$("#addressProvince").val(
											positionResult.regeocode.addressComponent.province);
									$("#addressCity").val(
											positionResult.regeocode.addressComponent.city);
									$("#addressCounty").val(
											positionResult.regeocode.addressComponent.district);
								});
								positionPicker.on('fail', function(
										positionResult) {

								});
								positionPicker.start();
							});
		}

		function onError(data) { //解析定位错误信息
			$("#addressInfo").text("定位失败");
		}
	}

</script>
</body>
</html>